package com.breaker.kata;


import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.stream.Collectors;

@Data
public class CodeCracker {
    private static final String ALPHABET = "abcdefghijklmnopqrstuvwxyz";
    private static final String DECRYPTION_KEY = "!)\"(£*%&><@abcdefghijklmno";
    private String password;

    public CodeCracker(String alphabet) {
        if (StringUtils.isNotEmpty(alphabet)) {
            this.password = Arrays.stream(alphabet.split("")).map(this::parsingPassword).collect(Collectors.joining());
        }
    }

    private String parsingPassword(String code) {
        if (ALPHABET.contains(code)) {
            int index = ALPHABET.indexOf(code);
            return DECRYPTION_KEY.substring(index, index + 1);
        }
        return code;
    }
}
